package com.dpj.threadpool;

import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

@Slf4j(topic = "c.TestInvokeAll")
public class TestInvokeAll {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        List<Future<String>> futures = executorService.invokeAll(Arrays.asList(() -> {
            log.debug("begging");
            Thread.sleep(100);
            return "1";
        }, () -> {
            log.debug("begging");
            Thread.sleep(100);
            return "2";
        }, () -> {
            log.debug("begging");
            Thread.sleep(100);
            return "2";
        }));

        log.debug("线程1返回值为{}",futures.get(0).get());
        log.debug("线程2返回值为{}",futures.get(1).get());
        log.debug("线程3返回值为{}",futures.get(2).get());
    }
}
